package com.agency8x.controller;

import java.util.List;

import com.agency8x.config.AppConf;
import com.agency8x.interceptor.CheckLoginInterceptor;
import com.agency8x.model.AuthRuleModel;
import com.agency8x.model.LoginModel;
import com.agency8x.model.base.BaseMenuItemModel;
import com.agency8x.web.util.WebRuntimeUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

/**
 * 首页控制器
 * 
 * IndexController
 */
@Before(CheckLoginInterceptor.class)
public class IndexController extends Controller {

	public void index() {
		// 获取用户登录信息
		LoginModel loginInfo = LoginModel.getLoginInfo(this, AppConf.loginSessionID);
		// 示例：loginInfo.getUserId(); // 获取user_id
		this.setAttr("loginInfo", loginInfo);                
                // 设置头像路径
                String face_url="/skin/theme/public/img/face.png";
                face_url=WebRuntimeUtil.me.existsFile("./WebRoot",loginInfo.getFaceUrl())?loginInfo.getFaceUrl():face_url;
                this.setAttr("face_url",face_url);
                
		if (loginInfo.getMemberUid() > 0) {
			// 代理
			this.render("agencyindex.html");
		} else {
			// 管理员
			// 获取菜单列表
			List<BaseMenuItemModel> menuList = AuthRuleModel.me.getMenus(loginInfo.getUserId());
			this.setAttr("menuList", menuList);
			this.render("index.html");
		}
	}
}